home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / room3d / mdrivers.bas < prev    next >
BASIC Source File  |  1999-03-10  |  6KB  |  147 lines

  1. Attribute VB_Name = "mDrivers"
  2. Option Explicit
  3.     
  4. ' Declare needed API calls
  5.     Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal Destination As Long, ByVal source As Long, ByVal length As Long)
  6.  
  7. ' Driver type for enumeration of D3D driver...
  8.     Public Type tD3DDriver
  9.         DESC    As String                         ' Driver description
  10.         NAME    As String                         ' Driver name
  11.         GUID    As Byte                           ' Unique interface ID for accessing driver
  12.         GUID1   As Byte                           ' ...
  13.         GUID2   As Byte                           ' ...
  14.         GUID3   As Byte                           ' ...
  15.         GUID4   As Byte                           ' ...
  16.         GUID5   As Byte                           ' ...
  17.         GUID6   As Byte                           ' ...
  18.         GUID7   As Byte                           ' ...
  19.         GUID8   As Byte                           ' ...
  20.         GUID9   As Byte                           ' ...
  21.         GUID10  As Byte                           ' ...
  22.         GUID11  As Byte                           ' ...
  23.         GUID12  As Byte                           ' ...
  24.         GUID13  As Byte                           ' ...
  25.         GUID14  As Byte                           ' ...
  26.         GUID15  As Byte                           ' ...
  27.         DEVDESC As D3DDEVICEDESC                  ' Device description for use by D3DRM
  28.         HDW     As Boolean                        ' Device is hardware
  29.         EMU     As Boolean                        ' Device is software-emulated
  30.         RGB     As Boolean                        ' Device has rgb caps
  31.         MONO    As Boolean                        ' Device has mono ramp caps
  32.     End Type
  33.     
  34. ' Driver Array for driver detection ...
  35.     Public G_dD3DDriver() As tD3DDriver                 ' Drivers for use with Direct3DRM
  36.     Public G_nD3DDriverCount As Integer                 ' Count of drivers
  37.     Global G_dD3DSelectedDriver As tD3DDriver           ' Driver to use
  38.     
  39. ' ENUMDEVICECALLBACK: Enumerates Device drivers for Direct3D
  40. Public Function EnumDeviceCallback(nGUID As Long, nDDDesc As Long, nDDName As Long, dHALDDDesc As D3DDEVICEDESC, dHELDDDesc As D3DDEVICEDESC, nOptions As Long) As Long
  41.  
  42.     ' Setup local variables ...
  43.     
  44.         Dim L_nTemp(256) As Byte                      ' Temporary array for name and guid translation
  45.         Dim L_nChar As Byte                           ' Temporary charactar for name translation
  46.         Dim L_nIndex As Long                          ' Variable to run through temp array
  47.         Dim L_dD3DDriver As tD3DDriver
  48.         
  49.     ' Process current driver ...
  50.     
  51.         ' Inspect current driver
  52.         With L_dD3DDriver
  53.             
  54.         ' Set driver capabilities...
  55.           
  56.             ' Decide if hardware supports color model and enable HAL or HEL support properly
  57.             If dHALDDDesc.dcmColorModel Then
  58.               .DEVDESC = dHALDDDesc
  59.               .HDW = True
  60.             Else
  61.               .DEVDESC = dHELDDDesc
  62.             End If
  63.  
  64.             ' Set RGB capability
  65.             .RGB = (.DEVDESC.dcmColorModel = D3DCOLOR_RGB)
  66.             ' Set emulation mode
  67.             .EMU = (Not .HDW)
  68.             ' Set mono ramp mode
  69.             .MONO = (Not .RGB)
  70.             
  71.         ' Decide if driver fits application needs ...
  72.         
  73.             ' Exit without naming/enabling driver if no RGB support
  74. '            If Not .RGB Then
  75. '                EnumDeviceCallback = DDENUMRET_OK
  76. '                Exit Function
  77. '            End If
  78.         
  79.             ' Exit without naming/enabling driver if no support for minimum 8 bit color depth
  80. '            If ((.DEVDESC.dwDeviceRenderBitDepth And DDBD_8) = 0) And ((.DEVDESC.dwDeviceRenderBitDepth And DDBD_16) = 0) And ((.DEVDESC.dwDeviceRenderBitDepth And DDBD_24) = 0) And ((.DEVDESC.dwDeviceRenderBitDepth And DDBD_32) = 0) Then
  81. '                EnumDeviceCallback = DDENUMRET_OK
  82. '                Exit Function
  83. '            End If
  84.             
  85.         End With
  86.             
  87.     ' DRIVER ACCEPTED ...
  88.     
  89.         ' Prepare space for driver
  90.         G_nD3DDriverCount = G_nD3DDriverCount + 1
  91.         ReDim Preserve G_dD3DDriver(G_nD3DDriverCount)
  92.         
  93.         ' Add driver to driver list
  94.         G_dD3DDriver(G_nD3DDriverCount) = L_dD3DDriver
  95.         
  96.         ' Set driver info
  97.         With G_dD3DDriver(G_nD3DDriverCount)
  98.     
  99.             ' Copy GUID data into temporary array
  100.             CopyMemory VarPtr(L_nTemp(0)), VarPtr(nGUID), 16
  101.             
  102.             ' Set GUID data into driver structure
  103.             .GUID = L_nTemp(0)
  104.             .GUID1 = L_nTemp(1)
  105.             .GUID2 = L_nTemp(2)
  106.             .GUID3 = L_nTemp(3)
  107.             .GUID4 = L_nTemp(4)
  108.             .GUID5 = L_nTemp(5)
  109.             .GUID6 = L_nTemp(6)
  110.             .GUID7 = L_nTemp(7)
  111.             .GUID8 = L_nTemp(8)
  112.             .GUID9 = L_nTemp(9)
  113.             .GUID10 = L_nTemp(10)
  114.             .GUID11 = L_nTemp(11)
  115.             .GUID12 = L_nTemp(12)
  116.             .GUID13 = L_nTemp(13)
  117.             .GUID14 = L_nTemp(14)
  118.             .GUID15 = L_nTemp(15)
  119.             
  120.             ' Copy driver name into temporary array
  121.             CopyMemory VarPtr(L_nTemp(0)), VarPtr(nDDName), 255
  122.               
  123.             ' Parse name of driver
  124.             For L_nIndex = 0 To 255
  125.                 L_nChar = L_nTemp(L_nIndex)
  126.                 If L_nChar < 32 Then Exit For
  127.                 .NAME = .NAME + Chr(L_nChar)
  128.             Next
  129.             
  130.             ' Copy driver Description into temporary array
  131.             CopyMemory VarPtr(L_nTemp(0)), VarPtr(nDDDesc), 255
  132.               
  133.             ' Parse description of driver
  134.             For L_nIndex = 0 To 255
  135.                 L_nChar = L_nTemp(L_nIndex)
  136.                 If L_nChar < 32 Then Exit For
  137.                 .DESC = .DESC + Chr(L_nChar)
  138.             Next
  139.             
  140.         End With
  141.             
  142.     ' Return success
  143.     EnumDeviceCallback = DDENUMRET_OK
  144.  
  145. End Function
  146.  
  147.